package bjf

import (
	"net/http"
)


type _Client struct {
  BaseURL string
  Servers []string
  TimeOut int64
  client *http.Client
}

var client _Client

func SetBaseUrl(url interface{}){
  switch tu := url.(type) {
    case int:
      client.BaseURL = client.Servers[tu]
    case string:
      client.BaseURL = tu;
  }
}

func (c *_Client) Do(req *http.Request) (*http.Response, error) {
	return c.client.Do(req)
}

func init(){
    {{ with .SelectedServer}}// 使用服务器：{{ .Description }}  
    client.BaseURL = "{{ .URL | get_path_from_url }}";
    {{end}}{{ range $key, $server := .Servers }}
    // {{ $server.Description }}
    // client.BaseURL = '{{ $server.URL }}',
    {{ end }}
    client.Servers = []string{ {{join (urls $.Servers) ","}} }
    // 打开下一行，修改请求超时时间，当前例子为10s
    client.TimeOut = 10 * 1000
}